package cn.edu.tju.scs.leave.service.impl;

import cn.edu.tju.scs.leave.dao.UserDao;
import cn.edu.tju.scs.leave.entity.User;
import cn.edu.tju.scs.leave.exception.UserException;
import cn.edu.tju.scs.leave.service.UserService;
import cn.edu.tju.scs.leave.utils.PasswordUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by haoxiaotian on 2016/9/3 2:08.
 */

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User hasMathUser(String phone, String password) {
        if(phone == null || "".equals(phone.trim())){
            throw new UserException(UserException.NULL_USERNAME_EXCEPTION);
        }

        if(password == null || "".equals(password.trim())){
            throw new UserException(UserException.NULL_PASSWORD_EXCEPTION);
        }
        Long phoneNum;
        try{
            phoneNum = Long.valueOf(phone.trim());
        }catch (NumberFormatException e){
            throw new UserException(UserException.NULL_USERNAME_EXCEPTION);
        }
        return userDao.queryUserByIdCard(phoneNum);
    }
}
